#!/bin/bash

ARG=$1
VERSION=${2-'latest'}

if [ -z "$ARG" ]; then
    echo "[ build | run | stop | logs | tag | push ]"
    exit 1
fi

if [ "$ARG" == "build" ]; then
    # image build
    CURRENT_DATE=$(date "+%Y-%m-%d %H:%M:%S")
    docker build \
    --build-arg INPUT_DATE="${CURRENT_DATE}" \
    --build-arg JAR_FILE=./target/supreme-secret-server-0.0.1.jar \
    --platform linux/amd64 \
    --no-cache \
    -t majewing/supreme-secret-server: $TAG -f ./Dockerfile .
elif [ "$ARG" == "run" ]; then
    CONTAINER_DIR="${HOME}/Development/docker-data/supreme-server/supreme-secret-server"
    docker run \
        --rm \
        --platform linux/x86_64 \
        --name supreme-secret-server \
        -p 7251:7250 \
        -e SECRET_USERNAME="administrator" \
        -e SECRET_PASSWORD="admin8uhb2wsx" \
        -v $CONTAINER_DIR/logs:/home/supreme-secret-server/logs \
        -d supreme-secret-server: $TAG
elif [ "$ARG" == "stop" ]; then
    docker stop supreme-secret-server
elif [ "$ARG" == "logs" ]; then
    docker logs -f supreme-secret-server
elif [ "$ARG" == "tag" ]; then
    docker tag supreme-secret-server: $TAG majewing/supreme-secret-server: $TAG
elif [ "$ARG" == "push" ]; then
    docker push majewing/supreme-secret-server: $TAG
elif [ "$ARG" == "package" ]; then
    mvn -Dmaven.test.skip -U clean package
fi





